#include "widget.h"
#include "ui_widget.h"
#include <QThread>
#include "clienthandle.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    server = new MyTcpServer;

    server->listen(QHostAddress::AnyIPv4,PORT);


}

Widget::~Widget()
{
    delete ui;
}

// void Widget::newClientHandler()
// {

//     ui->ipLineEdit->setText(socket->peerAddress().toString());
//     ui->portLineEdit->setText(QString::number(socket->peerPort()));

// }


// void Widget::clientInfoSlot()
// {
//     //获取信号的发送者
//     QTcpSocket *s = (QTcpSocket *)sender();
//     ui->mainLineEdit->setText(QString(s->readAll()));
// }

// void Widget::threadSlot(QByteArray b)
// {
//     ui->mainLineEdit->setText(QString(b));
// }

void Widget::on_clearpushButton_clicked()
{
    ui->sendLineEdit->clear();
}



void Widget::on_sendpushButton_clicked()
{
    //设置发送按钮的快捷键
    this->ui->sendpushButton->setShortcut(Qt::Key_Enter | Qt::Key_Return);
    QByteArray ba;
    ba.append((ui->sendLineEdit->text()).toUtf8());
    socket->write(ba);
}

